<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use VueRender\Render\Build;
use VueRender\Schema\Button;
use VueRender\Schema\Element;
use VueRender\Schema\Slot;
use VueRender\Schema\Input;


/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

function makePageComponent($fileName, $filepath){
    $button = new Button("测试：{{state.age}}岁");
    $button->onClick("onTest","()=>{state.age++;console.log(state,btnRef)}");
    $button->type("primary");
    $button->domRef("btnRef");
    $button->bind("size","btnSize","large");
    $button->state("age",18);

    $slot = new Slot();

    $ageInput = new Input();
    $ageInput->modelValue("age",20);

    $element1 = new Element("测试");
    $element1->prop("class","text-red");
    $element = new Element([$button,$slot,$ageInput, $element1]);


    $build = Build::make($fileName, $element, $filepath);
    $build->ref("btnRef");
//    ErrorPageRenderer
//    'import dateFns from "https://cdnjs.cloudflare.com/ajax/libs/date-fns/1.30.1/date_fns.min.js"',
    return $build->render();
}

Route::get('/layout', function (Request $request) {
    $fileName = $request->get("filename");
    $filepath = $request->get("filepath");
    $filepath = $filepath??"";
    return makePageComponent($fileName, $filepath);
});


Route::get('/', function () {
    return view("welcome");
});
